package com.hz.mybatistest.controller;

import com.hz.mybatistest.service.UserService;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.jms.Queue;

@RestController
public class UserController {

    @Resource
    UserService userService;

    @Resource
    JmsMessagingTemplate jmsMessagingTemplate;

    @Resource
    Queue queue;

    @PostMapping("/user/add")
    public String addUser(@RequestParam("username") String username, @RequestParam("realname") String realname,
                          @RequestParam("studentId") String studentId, @RequestParam("password") String password,
                          @RequestParam("userType") int userType) {
        userService.addUser(username, realname, studentId, password, userType);
        return "success";
    }

    @PostMapping("/user/login")
    public String login (@RequestParam("username") String username,@RequestParam("password") String password){
        jmsMessagingTemplate.convertAndSend(queue,username+" try to login");
        return userService.login(username,password)?"login success":"error username or password";
    }

    //1234567

}
